package com.hualan.controller;

import com.github.pagehelper.PageInfo;
import com.hualan.pojo.PricingType;
import com.hualan.pojo.Result;
import com.hualan.service.PriceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hdx")
public class PriceTypeController {
    @Autowired
    private PriceTypeService priceTypeService;

    @GetMapping("/selectType")
    public Result selectType(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize, String type){
        PageInfo<PricingType> pricingTypePageInfo = priceTypeService.selectType(pageNum, pageSize, type);
        return Result.success(pricingTypePageInfo);
    }
    @DeleteMapping("/deleteType/{id}")
    public Result deleteType(@PathVariable Long id){
        int i = priceTypeService.deleteType(id);
        if (i != 0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }
    @PostMapping("/insertType")
    public Result insertType(@RequestBody PricingType record){
        int i = priceTypeService.insertType(record);
        if (i != 0){
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }

    @GetMapping("/updateType")
    public Result updateType(Integer id,String type){
        int i = priceTypeService.updateType(id, type);
        if (i != 0){
            return Result.success("更新成功");
        }
        return Result.error("更新失败");
    }

    @DeleteMapping("/BatchType")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        int i = priceTypeService.deleteBatch(ids);
        if (i != 0){
            return Result.success("批量删除成功");
        }
        return Result.error("批量删除失败");
    }
}
